package com.caigou.modules.info.adapter

import android.graphics.Color
import android.text.TextUtils
import android.widget.ImageView
import android.widget.TextView
import com.caigou.comm.base.utils.ImageLoader
import com.caigou.modules.info.R
import com.caigou.modules.info.bean.InfoItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder


/**
 * @author #Suyghur.
 * Created on 2021/09/23
 */
class InfoItemAdapter(dataset: MutableList<InfoItemBean>) : BaseQuickAdapter<InfoItemBean, BaseViewHolder>(R.layout.item_info_list, dataset), LoadMoreModule {

    init {
        addChildClickViewIds(R.id.item_info_iv_like)
    }

    override fun convert(holder: BaseViewHolder, item: InfoItemBean) {
        ImageLoader.load(context, item.cover, holder.getView(R.id.item_info_iv_cover))
        holder.setText(R.id.item_info_tv_cover_num, "共${item.imgs.size}张")

        if (TextUtils.isEmpty(item.userInfo.headImg)) {
            holder.getView<ImageView>(R.id.item_info_iv_avatar).setImageResource(R.drawable.img_comm_avatar)
        } else {
            ImageLoader.loadCircle(context, item.userInfo.headImg, holder.getView(R.id.item_info_iv_avatar))
        }

        holder.setText(R.id.item_info_tv_nickname, item.userInfo.nickName)
        holder.setText(R.id.item_info_tv_title, item.title)
        holder.setText(R.id.item_info_tv_content, item.content)

        val ivLike = holder.getView<ImageView>(R.id.item_info_iv_like)
        val tvLikeNum = holder.getView<TextView>(R.id.item_info_tv_like_num)
        tvLikeNum.text = item.nicePoint.toString()
        if (item.like) {
            ivLike.setImageResource(R.drawable.img_info_like)
            tvLikeNum.setTextColor(Color.parseColor("#FE6880"))
        } else {
            ivLike.setImageResource(R.drawable.img_info_unlike)
            tvLikeNum.setTextColor(Color.parseColor("#505050"))
        }
    }

}